package com.example.demo.web.rest.controller;

import com.example.demo.client.evt.sysbasequery.QueryCodeEvt;
import com.example.demo.domain.Code;
import com.ffcs.oss.param.out.ServiceResp;
import com.ffcs.oss.param.vm.QueryPageVm;
import com.example.demo.service.CodeService;
import com.example.demo.web.rest.evt.IdEvt;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 字典值管理
 * @Author zhengmf
 * @Date 2018/12/28  16:42
 */
@Api("字典值管理")
@RestController
@RequestMapping("/api/code")
public class CodeController extends BaseController {
    @Autowired
    private CodeService codeService;

    @ApiOperation("刷新字典值缓存")
    @PostMapping(value = "/refreshAll")
    public ServiceResp refreshAllCode(){
        return baseQueryClient.refreshAllCode();
    }

    @ApiOperation("查询字典值")
    @PostMapping(value = "/queryCode")
    public ServiceResp<QueryPageVm<Code>> queryCode(@RequestBody QueryCodeEvt evt){
        return baseQueryClient.queryCode(evt);
    }

    @ApiOperation("保存字典值")
    @PostMapping(value = "/saveCode")
    public ServiceResp<Boolean> saveCode(@RequestBody @Validated Code code){
        codeService.saveCode(code);
        baseQueryClient.refreshAllCode();
        return ServiceResp.getInstance(Boolean.class).success(true);
    }

    @ApiOperation("根据id删除字典值，逻辑删除")
    @PostMapping(value = "/delCodeById")
    public ServiceResp<Boolean> delCodeById(@RequestBody @Validated IdEvt evt){
        codeService.updateStatus(evt.getId());
        baseQueryClient.refreshAllCode();
        return ServiceResp.getInstance(Boolean.class).success(true);
    }

}
